package com.runtu.domain.activity.service.discount.impl;

import com.runtu.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import com.runtu.domain.activity.service.discount.AbstractDiscountCalculateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName ZJCalculateService
 * @Description 直减
 * @date 2025/7/19 20:43
 * @Version 1.0
 */
@Slf4j
@Service("ZJ")
public class ZJCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {

        String marketExpr = groupBuyDiscount.getMarketExpr();
        BigDecimal x = new BigDecimal(marketExpr);
        BigDecimal subtractPrice = originalPrice.subtract(x);

        if (subtractPrice.compareTo(BigDecimal.ZERO) <= 0) {
            return new BigDecimal(0.01);
        }

        return subtractPrice;
    }
}
